package org.thanos.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.thanos.demo.model.Demo;
import org.thanos.demo.service.DemoService;

@RestController
@RequestMapping(path = "/api")
public class DemoController {

    @Autowired
    @Qualifier(value = "demoApi")
    private DemoService demoService;

    @GetMapping(path = "/demo", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> getDate() {
        try {
            return ResponseEntity.ok().body(demoService.hello());
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    @PostMapping(path = "/hello", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> getDate(@RequestBody Demo demo) {
        try {
            return ResponseEntity.ok().body(demoService.helloWorld(demo));
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
}
